rgba: Add GDK_RGBA() macro
authorBenjamin Otte <otte@redhat.com>
Tue, 14 May 2019 20:23:15 +0000 (22:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Tue, 21 May 2019 04:43:59 +0000 (06:43 +0200)
So far it's private, but it's a pretty cute way to use hex colors, so we
might conside making it public.

gdk/gdkrgbaprivate.h
gsk/gskrendernodeparser.c

index 58470e04c966065813b731efdf697ad70e1103d7..5126f573556106abd00d9db39e73d9fe20cbfa68 100644 (file)
 
 #include "gtk/css/gtkcssparserprivate.h"
 
+#define _GDK_RGBA_DECODE(c) ((unsigned)(((c) >= 'A' && (c) <= 'F') ? ((c)-'A'+10) : \
+                                        ((c) >= 'a' && (c) <= 'f') ? ((c)-'a'+10) : \
+                                        ((c) >= '0' && (c) <= '9') ? ((c)-'0') : \
+                                        -1))
+#define _GDK_RGBA_SELECT_COLOR(_str, index3, index6) _GDK_RGBA_DECODE (sizeof(_str) <= 4 ? (_str)[index3] : (_str)[index6])
+#define GDK_RGBA(str) ((GdkRGBA) {\
+    ((_GDK_RGBA_SELECT_COLOR(str, 0, 0) << 4) | _GDK_RGBA_SELECT_COLOR(str, 0, 1)) / 255., \
+    ((_GDK_RGBA_SELECT_COLOR(str, 1, 2) << 4) | _GDK_RGBA_SELECT_COLOR(str, 1, 3)) / 255., \
+    ((_GDK_RGBA_SELECT_COLOR(str, 2, 4) << 4) | _GDK_RGBA_SELECT_COLOR(str, 2, 5)) / 255., \
+    ((sizeof(str) % 4 == 1) ? ((_GDK_RGBA_SELECT_COLOR(str, 3, 6) << 4) | _GDK_RGBA_SELECT_COLOR(str, 3, 7)) : 0xFF) / 255 })
+
 
 gboolean               gdk_rgba_parser_parse                    (GtkCssParser           *parser,
                                                                  GdkRGBA                *rgba);
index 07e55fd7a2e8758f4eb3c9c8c0336376ecf23dd3..b6832347c237689dae204a4073856b606f4b6b46 100644 (file)
@@ -688,7 +688,7 @@ static GskRenderNode *
 parse_color_node (GtkCssParser *parser)
 {
   graphene_rect_t bounds = GRAPHENE_RECT_INIT (0, 0, 0, 0);
-  GdkRGBA color = { 0, 0, 0, 1 };
+  GdkRGBA color = GDK_RGBA("FF0000");
   const Declaration declarations[] = {
     { "bounds", parse_rect, NULL, &bounds },
     { "color", parse_color, NULL, &color },
@@ -732,7 +732,7 @@ static GskRenderNode *
 parse_inset_shadow_node (GtkCssParser *parser)
 {
   GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0);
-  GdkRGBA color = { 0, 0, 0, 1 };
+  GdkRGBA color = GDK_RGBA("000000");
   double dx = 1, dy = 1, blur = 0, spread = 0;
   const Declaration declarations[] = {
     { "outline", parse_rounded_rect, NULL, &outline },
@@ -753,7 +753,7 @@ parse_border_node (GtkCssParser *parser)
 {
   GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0);
   float widths[4] = { 1, 1, 1, 1 };
-  GdkRGBA colors[4] = { { 0, 0, 0, 1 }, {0, 0, 0, 1 }, {0, 0, 0, 1 }, { 0, 0, 0, 1 } };
+  GdkRGBA colors[4] = { GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000"), GDK_RGBA("000") };
   const Declaration declarations[] = {
     { "outline", parse_rounded_rect, NULL, &outline },
     { "widths", parse_float4, NULL, &widths },
@@ -794,7 +794,7 @@ static GskRenderNode *
 parse_outset_shadow_node (GtkCssParser *parser)
 {
   GskRoundedRect outline = GSK_ROUNDED_RECT_INIT (0, 0, 0, 0);
-  GdkRGBA color = { 0, 0, 0, 1 };
+  GdkRGBA color = GDK_RGBA("000000");
   double dx = 1, dy = 1, blur = 0, spread = 0;
   const Declaration declarations[] = {
     { "outline", parse_rounded_rect, NULL, &outline },
@@ -1005,7 +1005,7 @@ parse_text_node (GtkCssParser *parser)
 {
   PangoFont *font = NULL;
   graphene_point_t offset = GRAPHENE_POINT_INIT (0, 0);
-  GdkRGBA color = { 0, 0, 0, 1 };
+  GdkRGBA color = GDK_RGBA("000000");
   PangoGlyphString *glyphs = NULL;
   const Declaration declarations[] = {
     { "font", parse_font, clear_font, &font },